<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>账号:${account.userName}</legend>
        </fieldset>
    </div>
    <form id="roles" class="layui-form" action="" method="post">
        <#list roleGroups as group >
            <div class="layui-form-item">
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                    <legend>${group.name}</legend>
                </fieldset>
                <div class="layui-input-block">
                    <#list roleDTOList as roledto>
                        <#if group.code == roledto.group>
                            <#if (roledto.check)??>
                                <input type="checkbox" name='role[${roledto.id}]' value="${roledto.id}" title="${roledto.name}" checked="${roledto.check}">
                            <#else >
                                <input type="checkbox" name='role[${roledto.id}]' value="${roledto.id}" title="${roledto.name}">
                            </#if>
                        </#if>
                    </#list>
                </div>
            </div>
         </#list>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="addroles"  >立即提交</button>
            </div>
        </div>

    </form>
</div>
<script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/layuimini/lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>

<script>
    layui.use(['form','jquery'],function () {
        var form = layui.form,
            layer = layui.layer;
        form.render();
        form.on('submit(addroles)',function (data) {
            layer.alert(JSON.stringify(data.field));
            $.ajax({
                type:'post',
                url:'/account/addRoles/${account.id}',
                data:JSON.stringify(data.field),  //重点必须为一个变量如：data
                dataType:'json',
                contentType : "application/json",
                success:function(res){
                    //layer.alert(JSON.stringify(res));

                    var index = layer.alert(JSON.stringify(res), {
                        title: '最终的提交信息'
                    });

                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.location.reload();
                    parent.layer.close(iframeIndex);

                },
                error:function(){
                    layer.alert(JSON.stringify('失败'));
                }
            });
            return false;
        });

    });
</script>

</body>
</html>